//////// The Politics of status preservation: Immigration and the knowledge economy class \\\\\\\\

//////// Author: Briitta van Staalduinen \\\\\\\\

//// Description: Replication code for analyses \\\\

//// Dataset: INVEDUC \\\\

//// Code created: April 18, 2025 \\\\

// Set working directory \\ 

// Load data \\

use "inveduc.dta", clear

// Label variables in preparation for output \\

label var eduinc "KE class"

label var winner "KE class (binary)"

label var woman "Gender (1 = Woman)"

label var cohort3 "Cohort"

label var age "Age"

label var region "Region"

label var rankbot3 "Low-income min. share (rank)"

label var ranktop3 "High-income min. share (rank)"

label var rankunemp "Unemployed minority (rank)"

label var ranknonrout "KE minority (rank)"

label var bot3_immi2 "Low-income min. share"

label var top3_immi2 "High-income min. share"

label var unempr_noneu "Unemployed minority"

label var nonrout2_immi2 "KE minority"

label var redineq "Redistribution"

label var targedu "Social closure: Education"

label var accjob "Social closure: Employment"

////////////////////////////// SUMMARY \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

estpost summarize eduinc winner woman cohort3 age redineq targedu accjob bot3_immi2 top3_immi2 unempr_noneu nonrout2_immi2 

esttab, cells("count mean(fmt(%8.2f)) sd(fmt(%8.2f)) min(fmt(%8.2f)) max(fmt(%8.2f))") tex ///
nomtitles nonumbers nonote noobs label collabels("N" "Mean" "SD" "Min" "Max") ///
title("INVEDUC Summary statistics")


////////////////////////////// MAIN ANALYSIS, FIGURES 4-5 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


// FIGURE 4, SOCIAL CLOSURE: EDUcATION \\

estimates clear

reghdfe targedu c.rankbot3##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) 
margins winner, at(rankbot3 == (1(5)50)) post
est store mod1

reghdfe targedu c.ranktop3##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) 
margins winner, at(ranktop3 == (1(5)50)) post
est store mod2

coefplot (mod1, label(Minority share low-income) lp(dash)) (mod2, label(Minority share high-income)), vertical recast(line) ciopts(recast(rarea) fc(%33)) keep(*#1.winner*) xtitle("Region rank", margin(t+2)) title("") ytitle("Support social closure: Education", margin(t-5)) aspect(.8) xlabel(, format(%3.2f)) xlabel(1 "5" 2 "10" 3 "15" 4 "20" 5 "25" 6 "30" 7 "35" 8 "40" 9 "45" 10 "50") ylabel(1.5(.2)2.5) legend(position(6)) name(g7, replace)

reghdfe targedu c.rankunemp##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) 
margins winner, at(rankunemp == (1(5)50)) post
est store mod3

reghdfe targedu c.ranknonrout##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) 
margins winner, at(ranknonrout == (1(5)50)) post
est store mod4

coefplot (mod3, label(Minority share unemployed) lp(dash)) (mod4, label(Minority share KE employed)), vertical recast(line) ciopts(recast(rarea) fc(%33)) keep(*#1.winner*) xtitle("Region rank", margin(t+2)) title("") ytitle("Support social closure: Education", margin(t-5)) aspect(.8) xlabel(, format(%3.2f)) xlabel(1 "5" 2 "10" 3 "15" 4 "20" 5 "25" 6 "30" 7 "35" 8 "40" 9 "45" 10 "50") ylabel(1.5(.2)2.5) legend(position(6)) name(g8, replace)

graph combine g7 g8, cols(2)


// FIGURE 4, SOCIAL CLOSURE: EMPLOYMENT \\

reghdfe accjob c.rankbot3##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) 
margins winner, at(rankbot3 == (1(5)50)) post
est store mod5

reghdfe accjob c.ranktop3##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) 
margins winner, at(ranktop3 == (1(5)50)) post
est store mod6

coefplot (mod5, label(Minority share low-income) lp(dash)) (mod6, label(Minority share high-income)), vertical recast(line) ciopts(recast(rarea) fc(%33)) keep(*#1.winner*) xtitle("Region rank", margin(t+2)) title("") ytitle("Support social closure: Employment", margin(t-5)) aspect(.8) xlabel(, format(%3.2f)) xlabel(1 "5" 2 "10" 3 "15" 4 "20" 5 "25" 6 "30" 7 "35" 8 "40" 9 "45" 10 "50") ylabel(2.8(.2)3.8) legend(position(6)) name(g9, replace)

reghdfe accjob c.rankunemp##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) coeflegend
margins winner, at(rankunemp == (1(5)50)) post
est store mod7

reghdfe accjob c.ranknonrout##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) coeflegend
margins winner, at(ranknonrout == (1(5)50)) post
est store mod8

coefplot (mod7, label(Minority share unemployed) lp(dash)) (mod8, label(Minority share KE employed)), vertical recast(line) ciopts(recast(rarea) fc(%33)) keep(*#1.winner*) xtitle("Region rank", margin(t+2)) title("") ytitle("Support social closure: Employment", margin(t-5)) aspect(.8) xlabel(, format(%3.2f)) xlabel(1 "5" 2 "10" 3 "15" 4 "20" 5 "25" 6 "30" 7 "35" 8 "40" 9 "45" 10 "50") ylabel(2.8(.2)3.8) legend(position(6)) name(g10, replace)

graph combine g9 g10, cols(2)


// FIGURE A1, REDISTRIBUTION \\

reghdfe redineq c.rankbot3##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) 
margins winner, at(rankbot3 == (1(5)50)) post
est store modr1

reghdfe redineq c.ranktop3##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) 
margins winner, at(ranktop3 == (1(5)50)) post
est store modr2

coefplot (modr1, label(Share low-income) lp(dash)) (modr2, label(Share high-income)), vertical recast(line) ciopts(recast(rarea) fc(%33)) keep(*#1.winner*) xtitle("Region rank", margin(t+2)) title("") ytitle("Oppose redistribution", margin(t-5)) aspect(.8) xlabel(, format(%3.2f)) xlabel(1 "5" 2 "10" 3 "15" 4 "20" 5 "25" 6 "30" 7 "35" 8 "40" 9 "45" 10 "50") ylabel(1.8(.2)2.8) legend(position(6)) name(g11, replace)

reghdfe redineq c.rankunemp##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) 
margins winner, at(rankunemp == (1(5)50)) post
est store modr3

reghdfe redineq c.ranknonrout##i.winner woman cohort3 age unemp_nat reggdp, absorb(cntry) vce(robust) 
margins winner, at(ranknonrout == (1(5)50)) post
est store modr4

coefplot (modr3, label(Share unemployed) lp(dash)) (modr4, label(Share KE employed)), vertical recast(line) ciopts(recast(rarea) fc(%33)) keep(*#1.winner*) xtitle("Region rank", margin(t+2)) title("") ytitle("Oppose redistribution", margin(t-5)) aspect(.8) xlabel(, format(%3.2f)) xlabel(1 "5" 2 "10" 3 "15" 4 "20" 5 "25" 6 "30" 7 "35" 8 "40" 9 "45" 10 "50") ylabel(1.8(.2)2.8) legend(position(6)) name(g12, replace)

graph combine g11 g12, cols(2)


////////////////////////////// ROBUSTNESS CHECKS, APPENDIX TABLES A3-A5 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


// TABLE A6, SOCIAL CLOSURE: EDUCATION \\

estimates clear

xtmixed targedu woman cohort3 age c.eduinc##c.rankbot3 || cntry: || region:
estimates store m1, title(Model 1)
xtmixed targedu woman cohort3 age c.eduinc##c.ranktop3 || cntry: || region:
estimates store m2, title(Model 2)
xtmixed targedu woman cohort3 age c.eduinc##c.rankunemp|| cntry: || region:
estimates store m3, title(Model 3)
xtmixed targedu woman cohort3 age c.eduinc##c.ranknonrout || cntry: || region:
estimates store m4, title(Model 4)

esttab m1 m2 m3 m4, ///
tex cells(b(star fmt(3)) se(par fmt(2))) ///
   legend label varlabels(_cons constant)               ///
   stats(N, fmt(3 0 1) label(Observations)) star(* 0.05 ** 0.01 *** 0.001)

   
// TABLE A7, SOCIAL CLOSURE: EMPLOYMENT \\

estimates clear

xtmixed accjob woman cohort3 age c.eduinc##c.rankbot3 || cntry: || region:
estimates store m1, title(Model 1)
xtmixed accjob woman cohort3 age c.eduinc##c.ranktop3 || cntry: || region:
estimates store m2, title(Model 2)
xtmixed accjob woman cohort3 age c.eduinc##c.rankunemp || cntry: || region:
estimates store m3, title(Model 3)
xtmixed accjob woman cohort3 age c.eduinc##c.ranknonrout || cntry: || region:
estimates store m4, title(Model 4)

esttab m1 m2 m3 m4, ///
tex cells(b(star fmt(3)) se(par fmt(2))) ///
   legend label varlabels(_cons constant)               ///
   stats(N, fmt(3 0 1) label(Observations)) star(* 0.05 ** 0.01 *** 0.001)

   
// TABLE A8, REDISTRIBUTION \\

estimates clear

xtmixed redineq woman cohort3 age c.eduinc##c.rankbot3 || cntry: || region:
estimates store m1, title(Model 1)
xtmixed redineq woman cohort3 age c.eduinc##c.ranktop3 || cntry: || region:
estimates store m2, title(Model 2)
xtmixed redineq woman cohort3 age c.eduinc##c.rankunemp|| cntry: || region:
estimates store m3, title(Model 3)
xtmixed redineq woman cohort3 age c.eduinc##c.ranknonrout || cntry: || region:
estimates store m4, title(Model 4)

esttab m1 m2 m3 m4, ///
tex cells(b(star fmt(3)) se(par fmt(2))) ///
   legend label varlabels(_cons constant)               ///
   stats(N, fmt(3 0 1) label(Observations)) star(* 0.05 ** 0.01 *** 0.001)




